/**
 * 从本地获取token
 * @returns
 */
const TOKEN_NAME = 'news-token'

export const getToken = () => {
  return JSON.parse(localStorage.getItem(TOKEN_NAME)) || {}
}
/**
 * 把token存储到本地
 * @param {*} value
 */
export const setToken = value => {
  localStorage.setItem(TOKEN_NAME, JSON.stringify(value))
}
// 提供删除token方法
export function removesToken() {
  // 清空本地存储的token数据
  localStorage.removeItem(TOKEN_NAME)
}
/**
 *
 *
 * 封装添加的频道
 */
const CHANNEL_NAME = 'news-channel'
export const setChannel = value => {
  localStorage.setItem(CHANNEL_NAME, JSON.stringify(value))
}
export const getChannel = () => {
  return JSON.parse(localStorage.getItem(CHANNEL_NAME))
}

/**
 * 存储search 中的历史记录
 */
const HISTORY_NAME = 'news-history'
export const setHistory = value => {
  localStorage.setItem(HISTORY_NAME, JSON.stringify(value))
}
export const getHistory = () => {
  return JSON.parse(localStorage.getItem(HISTORY_NAME)) || []
}
